/**
 * 
 */
package jnzb.control.queue.change;

import jnzb.control.NZBProcessor;
import jnzb.control.events.InfoEventProcessor;
import jnzb.control.uiUpdate.UIUpdateDelegate;
import jnzb.model.nzb.NZB;

/**
 * @author AA1
 * 
 */
public class QueueRemoveChange extends QueueChangeProcessor {

	/**
	 * @param nzbProcessor
	 * @param uiDelegate
	 * @param infoProcessor
	 * @param selectedRow
	 */
	public QueueRemoveChange(NZBProcessor nzbProcessor,
			UIUpdateDelegate uiDelegate, InfoEventProcessor infoProcessor,
			int selectedRow) {
		super(nzbProcessor, uiDelegate, infoProcessor, selectedRow);
	}

	/**
	 * Checks if the deletion of this row will affect the current download. i.e
	 * is it the current download and is it not the only one?
	 * 
	 * @see jnzb.control.queue.change.QueueChangeProcessor#affectsDownload(int)
	 */
	@Override
	public boolean affectsDownload(int selectedRow) {
		// If this is the current download
		// check the size is > 1 because if we remove the only file and there
		// isnt another one, we won't send the new download notification adn the
		// thread will sit tere until it another download starts!
		return selectedRow == 0 && queueManager.getQueueSize() > 1;
	}

	/**
	 * Checks that the change has been made if the download was affected
	 * 
	 * @see jnzb.control.queue.change.QueueChangeProcessor#checkChangeMade(jnzb.model
	 *      .nzb.NZB)
	 */
	@Override
	public boolean checkChangeMade(NZB affectedNZB) {
		return !this.nzbProcessor.getCurrentNZB().equals(affectedNZB);
	}

	/**
	 * Removes the NZB from the queue
	 * 
	 * @see jnzb.control.queue.change.QueueChangeProcessor#makeQueueChange(jnzb.model
	 *      .nzb.NZB)
	 */
	@Override
	public void makeQueueChange(NZB affectedNZB) {
		this.queueManager.removeNZB(affectedNZB);
	}

	/**
	 * For remove we need to inform the nzb processor of change if its the
	 * current item but not listen for the action
	 * 
	 * @see jnzb.control.queue.change.QueueChangeProcessor#notifyNZBProcessorOfQueueChange()
	 */
	@Override
	protected void notifyNZBProcessorOfQueueChange() {
		// If this
		if (this.selectedRow == 0) {
			nzbProcessor.queueChanged();
		}
	}
}
